using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Security.Permissions;
using System.Drawing.Design;
using System.ComponentModel;
using System.Web.UI;
using System.Collections;

namespace CodeStory.WebControls
{

	[Editor(typeof(LinkItemCollectionEditor), typeof(UITypeEditor))]
	[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public sealed class LinkItemCollection : StateManagedCollection
	{
		// Fields
		private static readonly Type[] knownTypes = new Type[] { typeof(LinkItem), typeof(ScriptItem) };

		// Methods
		public int Add(BaseLinkItem spot) {
			return ((IList)this).Add(spot);
		}

		protected override object CreateKnownType(int index) {
			switch (index) {
				case 0:
					return new LinkItem();

				case 1:
					return new ScriptItem();
			}
			throw new ArgumentOutOfRangeException("HotSpotCollection_InvalidTypeIndex");
		}

		protected override Type[] GetKnownTypes() {
			return knownTypes;
		}

		public void Insert(int index, BaseLinkItem spot) {
			((IList)this).Insert(index, spot);
		}

		protected override void OnValidate(object o) {
			base.OnValidate(o);
			if (!(o is BaseLinkItem)) {
				throw new ArgumentException("HotSpotCollection_InvalidType");
			}
		}

		public void Remove(BaseLinkItem spot) {
			((IList)this).Remove(spot);
		}

		public void RemoveAt(int index) {
			((IList)this).RemoveAt(index);
		}

		protected override void SetDirtyObject(object o) {
			((BaseLinkItem)o).SetDirty();
		}

		// Properties
		public BaseLinkItem this[int index] {
			get {
				return (BaseLinkItem)((IList)this)[index];
			}
		}
	}

}
